home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / fspdev / fspdevTrace.c < prev    next >
C/C++ Source or Header  |  1990-10-11  |  6KB  |  253 lines

  1. /* 
  2.  * fsPdevTrace.c --
  3.  *
  4.  *    Routines for tracing the pseudo-device request-response protocol.
  5.  *
  6.  * Copyright 1987, 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/fspdev/RCS/fspdevTrace.c,v 9.2 90/10/11 13:27:36 kupfer Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <sprite.h>
  21. #include <fs.h>
  22. #include <fsconsist.h>
  23. #include <fsutil.h>
  24. #include <fspdev.h>
  25. #include <trace.h>
  26.  
  27. /*
  28.  * Prevent tracing by defining CLEAN here before this next include
  29.  */
  30. #undef CLEAN
  31. #include <fspdevInt.h>
  32. Boolean fspdev_Debug = FALSE;        /* Turns on print statements */
  33. Trace_Header fspdevTraceHdr;
  34. Trace_Header *fspdevTraceHdrPtr = &fspdevTraceHdr;
  35. int fspdevTraceLength = 50;
  36. Boolean fspdevTracing = TRUE;        /* Turns on circular trace */
  37. int fspdevMaxTraceDataSize;
  38. int fspdevTraceIndex = 0;
  39.  
  40.  
  41. /*
  42.  *----------------------------------------------------------------------------
  43.  *
  44.  * Fspdev_TraceInit --
  45.  *
  46.  *    Initialize the pseudo-device trace buffer.  Used for debugging
  47.  *    and profiling.
  48.  *
  49.  * Results:
  50.  *    None.
  51.  *
  52.  * Side effects:
  53.  *    Calls to the Trace module to allocate the trace buffer, etc.
  54.  *
  55.  *----------------------------------------------------------------------------
  56.  *
  57.  */
  58. ReturnStatus
  59. Fspdev_TraceInit()
  60. {
  61.     Trace_Init(fspdevTraceHdrPtr, fspdevTraceLength, sizeof(FspdevTraceRecord),
  62.         TRACE_NO_TIMES);
  63.     return SUCCESS;
  64. }
  65.  
  66. /*
  67.  *----------------------------------------------------------------------------
  68.  *
  69.  * Fspdev_PrintRec --
  70.  *
  71.  *    Print a record of the pseudo-device trace buffer.
  72.  *
  73.  * Results:
  74.  *    None.
  75.  *
  76.  * Side effects:
  77.  *    printf's
  78.  *
  79.  *----------------------------------------------------------------------------
  80.  *
  81.  */
  82. ReturnStatus
  83. Fspdev_PrintRec(clientData, event, printHeaderFlag)
  84.     ClientData clientData;    /* Client data in the trace record */
  85.     int event;            /* Type, or event, from the trace record */
  86.     Boolean printHeaderFlag;    /* If TRUE, a header line is printed */
  87. {
  88.     FspdevTraceRecord *recPtr = (FspdevTraceRecord *)clientData;
  89.     FspdevTraceRecType pdevEvent = (FspdevTraceRecType)event;
  90.     if (printHeaderFlag) {
  91.     /*
  92.      * Print column headers and a newline.
  93.      */
  94.     printf("%6s %17s %8s\n", "REC", "  <File ID>  ", " Event ");
  95.     }
  96.     if (recPtr != (FspdevTraceRecord *)NIL) {
  97.     /*
  98.      * Print out the fileID that's part of each record.
  99.      */
  100.     printf("%5d| ", recPtr->index);
  101.     printf("<%8x,%8x> ",
  102.       recPtr->fileID.major, recPtr->fileID.minor);
  103.  
  104.     switch(pdevEvent) {
  105.         case PDEVT_SRV_OPEN:
  106.         printf("Srv Open");
  107.         printf(" refs %d writes %d",
  108.                 recPtr->un.use.ref,
  109.                 recPtr->un.use.write);
  110.         break;
  111.         case PDEVT_CLT_OPEN:
  112.         printf("Clt Open");
  113.         printf(" refs %d writes %d",
  114.                 recPtr->un.use.ref,
  115.                 recPtr->un.use.write);
  116.          break;
  117.         case PDEVT_SRV_CLOSE:
  118.         printf("Srv Close");
  119.         printf(" refs %d writes %d",
  120.                 recPtr->un.use.ref,
  121.                 recPtr->un.use.write);
  122.          break;
  123.         case PDEVT_CLT_CLOSE:
  124.         printf("Clt Close");
  125.         printf(" refs %d writes %d",
  126.                 recPtr->un.use.ref,
  127.                 recPtr->un.use.write);
  128.          break;
  129.         case PDEVT_SRV_READ:
  130.         printf("Srv Read"); break;
  131.         case PDEVT_SRV_READ_WAIT:
  132.         printf("Srv Read Blocked"); break;
  133.         case PDEVT_SRV_SELECT:
  134.         printf("Srv Select Wait"); break;
  135.         case PDEVT_SRV_WRITE:
  136.         printf("Srv Write"); break;
  137.         case PDEVT_CNTL_READ:
  138.         printf("Control Read"); break;
  139.         case PDEVT_READ_WAIT:
  140.         printf("Wait for Read"); break;
  141.         case PDEVT_WAIT_LIST:
  142.         printf("Wait List Notify"); break;
  143.         case PDEVT_SELECT: {
  144.         printf("Select "); 
  145.         if (recPtr != (FspdevTraceRecord *)NIL ) {
  146.             if (recPtr->un.selectBits & FS_READABLE) {
  147.             printf("R");
  148.             }
  149.             if (recPtr->un.selectBits & FS_WRITABLE) {
  150.             printf("W");
  151.             }
  152.             if (recPtr->un.selectBits & FS_EXCEPTION) {
  153.             printf("E");
  154.             }
  155.         }
  156.         break;
  157.         }
  158.         case PDEVT_WAKEUP: {
  159.         /*
  160.          * Print the process ID from the wait info,
  161.          * and the select bits stashed in the wait info token.
  162.          */
  163.         printf("Wakeup");
  164.         if (recPtr != (FspdevTraceRecord *)NIL ) {
  165.             printf(" %x ", recPtr->un.wait.procID);
  166.             if (recPtr->un.wait.selectBits & FS_READABLE) {
  167.             printf("R");
  168.             }
  169.             if (recPtr->un.wait.selectBits & FS_WRITABLE) {
  170.             printf("W");
  171.             }
  172.             if (recPtr->un.wait.selectBits & FS_EXCEPTION) {
  173.             printf("E");
  174.             }
  175.         }
  176.         break;
  177.         }
  178.         case PDEVT_REQUEST: {
  179.         printf("Request");
  180.         if (recPtr != (FspdevTraceRecord *)NIL) {
  181.             switch(recPtr->un.requestHdr.operation) {
  182.             case PDEV_OPEN:
  183.                 printf(" OPEN"); break;
  184. #ifdef notdef
  185.             case PDEV_DUP:
  186.                 printf(" DUP"); break;
  187. #endif notdef
  188.             case PDEV_CLOSE:
  189.                 printf(" CLOSE"); break;
  190.             case PDEV_READ:
  191.                 printf(" READ"); break;
  192.             case PDEV_WRITE:
  193.                 printf(" WRITE"); break;
  194.             case PDEV_WRITE_ASYNC:
  195.                 printf(" WRITE_ASYNC"); break;
  196.             case PDEV_IOCTL:
  197.                 printf(" IOCTL"); break;
  198.             default:
  199.                 printf(" ??"); break;
  200.             }
  201.         }
  202.         break;
  203.         }
  204.         case PDEVT_REPLY: {
  205.         printf("Reply");
  206.         if (recPtr != (FspdevTraceRecord *)NIL) {
  207.             printf(" <%x> ", recPtr->un.reply.status);
  208.             if (recPtr->un.reply.selectBits & FS_READABLE) {
  209.             printf("R");
  210.             }
  211.             if (recPtr->un.reply.selectBits & FS_WRITABLE) {
  212.             printf("W");
  213.             }
  214.         }
  215.         break;
  216.         }
  217.         default:
  218.         printf("<%d>", event); break;
  219.  
  220.     }
  221.     }
  222.     return SUCCESS;
  223. }
  224.  
  225. /*
  226.  *----------------------------------------------------------------------
  227.  *
  228.  * Fspdev_PrintTrace --
  229.  *
  230.  *    Dump out the pdev trace.
  231.  *
  232.  * Results:
  233.  *    None.
  234.  *
  235.  * Side effects:
  236.  *    None.
  237.  *
  238.  *----------------------------------------------------------------------
  239.  */
  240.  
  241. void
  242. Fspdev_PrintTrace(clientData)
  243.     ClientData clientData;
  244. {
  245.     int numRecs = (int)clientData;
  246.  
  247.     if (numRecs < 0) {
  248.     numRecs = fspdevTraceLength;
  249.     }
  250.     printf("PDEV TRACE\n");
  251.     (void)Trace_Print(fspdevTraceHdrPtr, numRecs, Fspdev_PrintRec);
  252. }
  253.